﻿using BCCommon;
using BCDto.Common.ErrorMessage;
using BCDto.TMS.Order.OrderAssignRecord;
using BCService.TMS.Order.OrderAssignRecord;
using BCTMSRESTful.Configs;
using Microsoft.AspNetCore.Mvc;

namespace BCTMSRESTful.Controllers.Management.TMS.Order.OrderAssignRecord
{
    /// <summary>
    /// 订单指派记录
    /// </summary>
    [ApiExplorerSettings(GroupName = "TMSAdmin")]
    [Route("api/v1/sim/[controller]")]
    [ApiController]
    public class OrderAssignRecordController : ManagementBaseController
    {
        #region 私有变量
        private IOrderAssignRecordService orderAssignRecordService;
        #endregion

        #region 构造函数
        /// <summary>
        /// 构造函数
        /// </summary> 
        public OrderAssignRecordController(IOrderAssignRecordService orderAssignRecordService)
        {
            this.orderAssignRecordService = orderAssignRecordService;
        }
        #endregion


        #region 修改订单指派记录

        /// <summary>
        /// 修改订单指派记录
        /// </summary>
        /// <param name="dto"></param>
        /// <response code="200">修改订单指派记录</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPut]
        [Log("修改订单指派记录")]
        [ProducesResponseType(typeof(OrderAssignRecordDto), 200)]
        [ProducesResponseType(typeof(ErrorMessageDto), 400)]
        [ProducesResponseType(typeof(ErrorMessageDto), 401)]
        [ProducesResponseType(typeof(ErrorMessageDto), 500)]
        public IActionResult Put([FromBody] OrderAssignRecordDto dto)
        {
            return Ok(this.orderAssignRecordService.Update(dto));
        }
        #endregion

        #region 删除订单指派记录

        /// <summary>
        /// 删除订单指派记录
        /// </summary>
        /// <param name="orderAssignRecordId">订单指派ID</param>
        /// <response code="204">删除订单指派记录</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpDelete("{order_assign_record_id}")]
        [Log("删除订单指派纪录")]
        [ProducesResponseType(typeof(int), 200)]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        [ProducesResponseType(typeof(ErrorMessageDto), 400)]
        [ProducesResponseType(typeof(ErrorMessageDto), 500)]
        public IActionResult Delete([FromQuery(Name = "order_assign_record_id")] long orderAssignRecordId)
        {
            this.orderAssignRecordService.Delete(orderAssignRecordId);
            return NoContent();
        }
        #endregion

        #region 获取一条订单指派记录

        /// <summary>
        /// 获取一条订单指派记录
        /// </summary>
        /// <param name="orderAssignRecordId">订单指派ID</param>
        /// <response code="200">获取一条订单指派记录</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("{order_assign_record_id}")]
        [ProducesResponseType(typeof(OrderAssignRecordDto), 200)]
        [ProducesResponseType(typeof(ErrorMessageDto), 400)]
        [ProducesResponseType(typeof(ErrorMessageDto), 401)]
        [ProducesResponseType(typeof(ErrorMessageDto), 500)]
        public IActionResult Get([FromRoute(Name = "order_assign_record_id")] long orderAssignRecordId)
        {
            return (Ok(orderAssignRecordService.GetByOrderAssignRecordId(orderAssignRecordId)));

        }
        #endregion

        #region 分页查询订单指派记录

        /// <summary>
        /// 分页查询订单指派记录
        /// </summary>
        /// <param name="orderId">订单ID</param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <response code="200">查询订单指派</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<OrderAssignRecordDto>), 200)]
        [ProducesResponseType(typeof(ErrorMessageDto), 400)]
        [ProducesResponseType(typeof(ErrorMessageDto), 500)]
        public IActionResult Query(
            [FromQuery(Name = "order_id")] long? orderId,
            [FromQuery(Name = "index")] int? pageIndex = 1,
            [FromQuery(Name = "size")] int? pageSize = 10)
        {
            return Ok(this.orderAssignRecordService.GetList(this.Admin, orderId, pageIndex.Value, pageSize.Value));
        }
        #endregion
    }
}
